<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="机台编号" prop="maccode">
        <el-input
          v-model="queryParams.maccode"
          placeholder="请输入机台编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班次日期" prop="shiftdate">
        <el-date-picker clearable size="small"
          v-model="queryParams.shiftdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择班次日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="班次类别" prop="shifttype">
        <el-select v-model="queryParams.shifttype" placeholder="请选择班次类别" clearable size="small">
          <el-option
            v-for="dict in shifttypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="开始时间" prop="sjtime">
        <el-date-picker clearable size="small"
          v-model="queryParams.sjtime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择上轴时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="ljtime">
        <el-date-picker clearable size="small"
          v-model="queryParams.ljtime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择了机时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['mesana:warp:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table v-loading="loading" :data="warpList" @selection-change="handleSelectionChange">

      <el-table-column label="机台编号" align="center" prop="maccode" />
      <el-table-column label="班次日期" align="center" prop="shiftdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shiftdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="班次类别" align="center" prop="shifttype">
        <template slot-scope="scope">
          <dict-tag :options="shifttypeOptions" :value="scope.row.shifttype"/>
        </template>
      </el-table-column>


      <el-table-column label="平均车速(m/min)" align="center" prop="avgSpeed" />
      <el-table-column label="整经长度(m)" align="center" prop="curlength" />

      <el-table-column label="百根万米断头率" align="center" prop="breakrate" >
       <!-- <template slot-scope="scope">
          <span>{{ parseFloat(scope.row.breakrate*100).toFixed(2) }}</span>
        </template>-->
      </el-table-column>
      <el-table-column label="断头数" align="center" prop="breaknum" />

      <el-table-column label="操作员" align="center" prop="opworker">
        <template slot-scope="scope">
          <dict-tag :options="opworkerOptions" :value="scope.row.opworker"/>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listWarp, bancireport, exportWarp } from "@/api/mesana/warp";

export default {
  name: "Warp",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 整经数据汇总表格数据
      warpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 班次类别字典
      shifttypeOptions: [],
      // 是否跨班次字典
      iscrossshiftOptions: [],
      // 轴状态字典
      beamstatusOptions: [],
      // 操作员字典
      opworkerOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        maccode: null,
        shiftdate: null,
        shifttype: null,
        sjtime: null,
        ljtime: null,
        opworker: null,
      },

    };
  },
  created() {
    this.getList();
    this.getDicts("dict_shiftType").then(response => {
      this.shifttypeOptions = response.data;
    });

    this.getDicts("dict_warpworkers").then(response => {
      this.opworkerOptions = response.data;
    });
  },
  methods: {
    /** 查询总列表 */
    getList() {
      this.loading = true;
        bancireport(this.queryParams).then(response => {
        this.warpList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },




    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有整经数据汇总数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportWarp(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
